package com.dm.comm.vo;


import java.io.Serializable;

public class Result<T> implements Serializable {

    private boolean success;
    private String errorCode;
    private String msg;
    private T data;

    public Result(){}


    public Result(boolean success, String errorCode, String msg, T data) {
        this.success = success;
        this.errorCode = errorCode;
        this.msg = msg;
        this.data = data;
    }

    public Result(boolean success, String errorCode, String msg) {
        this.success = success;
        this.errorCode = errorCode;
        this.msg = msg;
    }

    /***
     * 统一返回成功的Result
     */
    public static Result success(String msg){
        Result result=new Result(true,StatusCode.OK,msg);
        return  result;
    }

    public static Result success(String msg,Object data){
        Result result=new Result(true,StatusCode.OK,msg,data);
        return  result;
    }

    public static Result fail(String msg){
        Result result=new Result(false,StatusCode.ERROR,msg);
        return  result;
    }

    public static Result unauth(){
        Result result=new Result(false,StatusCode.NO_LOGIN,"未登录");
        return  result;
    }



    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
